<?php include("header.php");
include("geocoder.php");
//echo "in new register";
$first_name =  mysql_real_escape_string($_POST["first_name"]);
$last_name =  mysql_real_escape_string($_POST["last_name"]);
$area_code = mysql_real_escape_string($_POST["phone_num1"]);
$phone_num = mysql_real_escape_string($_POST["phone_num2"]);
$phone_num2 = mysql_real_escape_string($_POST["phone_num3"]);
$street_address = mysql_real_escape_string($_POST["street_address"]);
$second_line = mysql_real_escape_string($_POST["line2"]);
$state = "CA";
$city = mysql_real_escape_string($_POST["city"]);
$zipcode = mysql_real_escape_string($_POST["zipcode"]);
$email =  mysql_real_escape_string($_POST["email"]);
//$post_until = $_POST["month"] + "/" + $_POST["day"] + "/" + $_POST["year"];
//$post_until =  mysql_real_escape_string($post_until);
$times =  mysql_real_escape_string($_POST["times"]);
$tree_info =  mysql_real_escape_string($_POST["tree_info"]);
$add_info =  mysql_real_escape_string($_POST["add_info"]);
$equipment = "";

$category = mysql_real_escape_string($_POST["category"]);
//$website = mysql_real_escape_string($_POST["website"]);
$password = mysql_real_escape_string($_POST["password"]);


$address = $street_address." ".$second_line." ".$state." ".$zipcode;
$geocodeAddress = preg_replace('/\s+/', '+', $address);
$query = <<<END
	SELECT MAX(`idpickup`) FROM `hestia`.`pickups2`;
END;

$result = mysql_query($query, $connection);

if ($result == false){
	mysql_close($connection);
	die("Registration Failed:".mysql_error($connection));
}

$result = mysql_fetch_array($result);

$geocode = geocode($geocodeAddress);
$lat = $geocode["lat"];
$lng = $geocode["lng"];
$query = <<<END
	INSERT INTO `hestia`.`pickups2`
	(`first_name`, `last_name`, `area_code`,
	`phone_num`, `phone_num2`, `street_address`, `second_line`,
	`city`, `zipcode`, `email`, `times`, `tree_info`,
	`equipment`, `add_info`, `reserved`, `lat`, `lng`,`category`,`password`)
	VALUES (
		'$first_name',
		'$last_name',
		'$area_code',
		'$phone_num',
		'$phone_num2',
		'$street_address',
		'$second_line',
		'$city', '$zipcode',
		'$email', '$times',
		'$tree_info', '$equipment',
		'$add_info', 'open',
		'$lat', '$lng','$category','$password');


END;
$result = mysql_query ( $query, $connection );

if ($result) {
	$query = "SELECT MAX(idpickup) FROM `pickups2`";
	$result =mysql_query ( $query, $connection );
	
	$result = mysql_fetch_array($result);
	$query = "SELECT * FROM `pickups2` WHERE `idpickup` = $result[0]"; 
	$result =mysql_query ( $query, $connection );
	
	if ($result) {
		$result = mysql_fetch_array($result);
		$output = <<<END
		<script type="text/javascript" src="jscripts/view.js"></script>
<script type="text/javascript" src="jscripts/calendar.js"></script>
<body id="form">


<div id="form_container">
<form id="form_158019" class="appnitro" method="post" action="new_register_submit.php">
<div class="form_description">
<h2>Food Registration Successful</h2>
<p>Thank you  for registering with Anteater Feeder</p>
</div>
</form>
</div>
</body>
END;
		echo $output;
	}
}
 include("footer.php"); ?>